package com.yhxd.modular.news.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 附件
 */
@Data
@Entity(name = "news_attachment")
@EntityListeners(value = AuditingEntityListener.class)
public class Attachment implements Serializable {

    @ApiModelProperty(value = "id")
    @Id
    @GeneratedValue(generator = "idGenerator")
    @GenericGenerator(name = "idGenerator", strategy = "com.yhxd.utils.IdUtils")
    @Column(name = "id")
    private Long id;

    @ApiModelProperty(value = "信息id")
    @Column(name = "news_id", insertable = false, updatable = false)
    private Long newsId;

    @JsonIgnore
    @ApiModelProperty(value = "信息")
    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinColumn(name = "news_id")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private News news;

    @ApiModelProperty(value = "附件路径")
    @Column(name = "file_path")
    private String filePath;

    @ApiModelProperty(value = "附件名称")
    @Column(name = "file_name")
    private String fileName;

    @ApiModelProperty(value = "附件重命名")
    @Column(name = "new_file_name")
    private String newFileName;

    @ApiModelProperty(value = "附件后缀")
    @Column(name = "file_suffix")
    private String fileSuffix;

    @ApiModelProperty(value = "创建人")
    @Column(name = "create_name")
    private String createName;

    @ApiModelProperty(value = "创建时间")
    @Temporal(TemporalType.TIMESTAMP)
    @CreatedDate
    @Column(name = "create_time")
    private Date createTime;

    @ApiModelProperty(value = "修改人")
    @Column(name = "update_name")
    private String updateName;

    @ApiModelProperty(value = "修改时间")
    @Temporal(TemporalType.TIMESTAMP)
    @LastModifiedDate
    @Column(name = "update_time")
    private Date updateTime;

    @ApiModelProperty(value = "数据是否可用，0不可用，1可用")
    @Column(name = "enable")
    private Integer enable = 1;

    @ApiModelProperty(value = "版本号")
    @Column(name = "version")
    private Integer version;
}
